package com.yaowen.loadpictures;

import android.graphics.Bitmap;
import android.os.Looper;
import android.os.Message;
import android.util.LruCache;

import java.util.LinkedList;
import java.util.concurrent.ExecutorService;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

/**
 * Created by HelloWorld on 2015/9/19.
 */
public class ImageLoader {
    private static  ImageLoader mInstance;
    //图片缓存的核心对象
    private LruCache<String,Bitmap> mLruCache;
    //线程池
    private ExecutorService mThreadPool;
    private static final int DEAFULT_THREAD_COUNT=1;
    //队列的调度方式
    private Type mType=Type.LIFO;
    //任务队列
    private LinkedList<Runnable> mTaskQueue;
    //后台轮询线程
    private Thread mPoolThread;
    private Handler mPoolThreadHandler;
    //UI线程中的Handler
    private Handler mUIHandler;
    public enum Type{
        FIFI,LIFO;
    }

    private ImageLoader(int threadCount,Type type){
        init(threadCount,type);
    }

    private void init(int threadCount, Type type) {
        //后台轮询线程
        mPoolThread=new Thread(){
            @Override
            public void run() {
                Looper.prepare();
               mPoolThreadHandler=new Handler() {
                   @Override
                   public void close() {

                   }

                   @Override
                   public void flush() {

                   }

                   @Override
                   public void publish(LogRecord record) {

                   }


                   public void handleMessage(Message msg) {
                        
                   }
               };
                Looper.loop();
            }
        };
        mPoolThread.start();
    }

    public static ImageLoader getmInstance(){
        if (mInstance==null){
            synchronized (ImageLoader.class){
                if (mInstance==null){
                    mInstance=new ImageLoader(DEAFULT_THREAD_COUNT,Type.LIFO);

                }
            }
        }
        return mInstance;
    }
}
